import React from 'react';
import { WeaTab, WeaLocaleProvider, WeaTools } from 'ecCom';
import { observer } from 'mobx-react';
import ProgramView from './programView/ProgramView';
import ProgramAuditList from './ProgramAuditList';
import ProgramList from './ProgramList';
import { getParams } from '../../util/Util'
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 考核方案
 * jiansong 2019/6/18
 */
@observer
export default class ProgramIndex extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
            selectedKey: "3",
            topTabCount: {},
            type: getParams("queryType"),
        }
    }

    componentWillMount() {
        this.updateNum();
        if (getParams("type")) {
            this.setState({
                selectedKey: getParams("type")
            })
        }
    }
    updateNum = () => {
        WeaTools.callApi('/api/workrelate/performance/accessAuditProgramNum', 'GET', {operation: "all"}).then((data) => {
            if (data.api_status) {
                this.setState({ topTabCount: { auditprogram: data.auditamount, searchprogram: data.nosetamount } });
            }
        });
    }
    render() {
        const { selectedKey, topTabCount } = this.state;
        let topTab = [
            { title: getLabel('506163', '我的考核方案'), viewcondition: "1", groupid: "myprogram" },
            { title: getLabel('506164', '待审核方案'), viewcondition: "2", groupid: "auditprogram", showcount: true, color: "#ff3232", },
            { title: getLabel('506165', '方案设置查询'), viewcondition: "3", groupid: "searchprogram", showcount: true, color: "#ff3232", }
        ];
        return (
            <div>
                <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@1cvgze`} datas={topTab}
                    counts={topTabCount}
                    keyParam="viewcondition"
                    countParam="groupid" //数量
                    selectedKey={selectedKey}
                    onChange={v => this.setState({ selectedKey: v })} />
                {selectedKey === "1" && <ProgramView ecId={`${this && this.props && this.props.ecId || ''}_ProgramView@4q4a0b`} height={true} />}
                {selectedKey === "2" && <ProgramAuditList ecId={`${this && this.props && this.props.ecId || ''}_ProgramAuditList@2i3bw7`} updateNum={() => this.updateNum()}/>}
                {selectedKey === "3" && <ProgramList ecId={`${this && this.props && this.props.ecId || ''}_ProgramList@j71wgb`} type={this.state.type} />}
            </div>
        )
    }

};